package com.springboot.blog.service;

import com.springboot.blog.beans.AdminUser;
import com.springboot.blog.beans.RoleName;
import com.springboot.blog.dao.AdminUserDao;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class AdminUserServiceImpl {

    @Resource
    private AdminUserDao adminUserDao;

    public void checkLogin(String userName,String userPassword,Boolean rememberMe) throws Exception{

        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(userName,userPassword,rememberMe);
        subject.login(token);
    }

    public int addAdminUser(String blogUsername,String blogPassword,String  blogPhone,String blogNickName,String blogPwdSalt){
        return adminUserDao.findAdmin(blogUsername,blogPassword,blogPhone,blogNickName,blogPwdSalt);
    }

    public AdminUser findAdmin(String userName, String userPhone){
        return adminUserDao.findAdminAndPhone(userName,userPhone);
    }

    public Boolean updateAdminUser(String userName,String userPwd,String blogPwdSalt){
        return adminUserDao.updateAdmin(userName,userPwd,blogPwdSalt);
    }

}
